package com.tg.app.activity.device.add;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.tg.app.R;
import com.tg.app.listener.OnAddDeviceListener;

public class Reset4gCarGuideFragment extends Fragment {
    private OnAddDeviceListener mOnAddDeviceListener;
    private int mParam;

    public Reset4gCarGuideFragment() {
    }

    public static Reset4gCarGuideFragment newInstance(int param) {
        Reset4gCarGuideFragment fragment = new Reset4gCarGuideFragment();
        Bundle args = new Bundle();
        args.putInt(AddFragmentTabActivity.EXT_DEVICE_ADD_TYPE, param);
        fragment.setArguments(args);
        return fragment;
    }
    public void setOnAddDeviceListener(OnAddDeviceListener onAddDeviceListener) {
        this.mOnAddDeviceListener = onAddDeviceListener;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam = getArguments().getInt(AddFragmentTabActivity.EXT_DEVICE_ADD_TYPE);
        }
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (getArguments() != null) {
            mParam = getArguments().getInt(AddFragmentTabActivity.EXT_DEVICE_ADD_TYPE);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View  view =  inflater.inflate(R.layout.fragment_reset_4g_car_guide, container, false);
        TextView textTip = view.findViewById(R.id.tv_device_wifi_add_title);
        if (mParam == AddFragmentTabActivity.DEVICE_ADD_TYPE_QRCODE_SCAN){
            textTip.setText(R.string.wifi_4g_device_add);
        }

        CheckBox cbListener = view.findViewById(R.id.cb_listener);
        final Button button = view.findViewById(R.id.btn_before_add_next);
        button.setAlpha(0.4f);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    if (mOnAddDeviceListener !=null){
                        mOnAddDeviceListener.onClickBtnForDevice();
                    }
            }
        });
        cbListener.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                button.setEnabled(b);
                if (b){
                    button.setAlpha(1f);
                }else {
                    button.setAlpha(0.4f);
                }
            }
        });
        return view;
    }
}
